//
//  IndicatorView.swift
//  StoreProject
//
//  Created by CYC on 1998/1/5.
//

// 风火轮提示

import UIKit

class IndicatorView: UIView {

    // 显示
    static func show(_ view: UIView) {
        
        self.hide(view)
        
        // 覆盖整个父视图，接收点击事件
        let indicatorView = IndicatorView.init(frame: view.bounds)
        view.addSubview(indicatorView)
        
        // 方块背景
        let size = CGFloat(80.0)
        let bgView = UIView.init(frame: .init(x: (indicatorView.c_width() - size)/2.0, y: (indicatorView.c_height() - size)/2.0, width: size, height: size))
        bgView.backgroundColor = kRGBAColor(0, 0, 0, 0.8)
        bgView.c_radius(radius: 15)
        indicatorView.addSubview(bgView)
        
        // 菊花
        let catorView = UIActivityIndicatorView.init(frame: bgView.bounds)
        catorView.style = .whiteLarge
        catorView.startAnimating()
        bgView.addSubview(catorView)
    }
    
    // 移除
    static func hide(_ view: UIView) {
        
        for v in view.subviews {
            if v.isKind(of: IndicatorView.self) {
                v.removeFromSuperview()
            }
        }
    }

}
